package com.hotel.service.impl;  
  
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hotel.dao.mapper.UserMapper;
import com.hotel.entity.User;
import com.hotel.entity.UserExample;
import com.hotel.entity.UserResult;
import com.hotel.service.UpdateService;
import com.hotel.utils.Message;




  
@Service("indexService")  
public class UpdateServiceImpl implements UpdateService {
	
	@Resource  
    private UserMapper userMapper;
	
	@Override
	public UserResult selectName(String username) {
		UserResult ur = new UserResult();
		UserExample example = new UserExample();
		UserExample.Criteria criteria = example.createCriteria();
		criteria.andAccountEqualTo(username);
		List<User> list = userMapper.selectByExample(example);
		
		if(list.isEmpty()){
			ur.setMessage(Message.Message_5000);
		}
		ur.setMessage(Message.Message_4000);
		ur.setUser(list.get(0));
		return ur;
	}

	@Override
	public UserResult updateUser(User user) {
		UserResult ur = new UserResult();
		UserExample example = new UserExample();
		UserExample.Criteria criteria = example.createCriteria();
		criteria.andAccountEqualTo(user.getAccount());
		int i = userMapper.updateByExample(user, example);
		
		
		if(i == 1){
			ur.setMessage(Message.Message_4001);
		}
		else{
			ur.setMessage(Message.Message_5001);
		}
		
		ur.setUser(user);
		return ur;
		
	}  

	

}